package com.jingtai.shop.service.goods.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jingtai.common.enums.ActivityEnum;
import com.jingtai.common.enums.DeleteFlagEnum;
import com.jingtai.common.enums.GoodsStatusEnum;
import com.jingtai.common.enums.NewProductsEnum;
import com.jingtai.core.entity.shop.MerchantsGoods;
import com.jingtai.core.entity.shop.MerchantsGoodsWarehouse;
import com.jingtai.core.mapper.shop.MerchantsGoodsWarehouseMapper;
import com.jingtai.shop.service.goods.MerchantsGoodsService;
import com.jingtai.shop.service.goods.MerchantsGoodsWarehouseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商户商品属性表 服务实现类
 * </p>
 *
 * @author GR123
 * @since 2020-11-29
 */
@Service
public class MerchantsGoodsWarehouseServiceImpl extends ServiceImpl<MerchantsGoodsWarehouseMapper, MerchantsGoodsWarehouse> implements MerchantsGoodsWarehouseService {

    @Resource
    private MerchantsGoodsWarehouseService goodsWarehouseService;
    @Resource
    private MerchantsGoodsService merchantsGoodsService;

    /**
     * 商品详请->展示商品的规格参数
     */
    @Override
    public Map<String, Object> showShopAttribute(String goodsCode) {
        Map<String, Object> map = new HashMap<>(2);
        List<MerchantsGoodsWarehouse> goodsWarehouseList = goodsWarehouseService.list(Wrappers.lambdaQuery(MerchantsGoodsWarehouse.class)
                .eq(MerchantsGoodsWarehouse::getGoodsCode, goodsCode)
                .eq(MerchantsGoodsWarehouse::getDeleteFlag, DeleteFlagEnum.NOT_DELETE.getCode()));
        map.put("parameter","");
        map.put("attribute",goodsWarehouseList);
        return map;
    }

    @Override
    public Page<MerchantsGoods> showStoreGoods(Long storeId,Integer type, Long pageNo, Long pageSize) {
        return merchantsGoodsService.page(new Page<MerchantsGoods>(pageNo,pageSize),Wrappers.lambdaQuery(MerchantsGoods.class).eq(MerchantsGoods::getStoreId,storeId).eq(MerchantsGoods::getGoodsState, GoodsStatusEnum.NORMAL.getStatus()).eq(MerchantsGoods::getDeleteFlag,DeleteFlagEnum.NOT_DELETE.getCode()).eq(type == 1,MerchantsGoods::getIsNewProducts,NewProductsEnum.TRUE.getStatus()).eq(type == 2,MerchantsGoods::getIsActivity,ActivityEnum.TRUE.getStatus()).orderByDesc(MerchantsGoods::getCreateTime));
    }
}
